# 高效数值数组
import array
import random

arr = array.array('f', [random.randrange(-10, 10) for _ in range(10)])
# array('f', [5.0, 9.0, -6.0, -10.0, 8.0, -1.0, -7.0, -1.0, -8.0, -10.0])
print(arr)
arr = array.array('i', [i for i in range(10)])
print(arr)  # array('i', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
print(array.typecodes, arr.typecode)  # bBuhHiIlLqQfd f
print(arr.index(2))  # 2
print(arr.buffer_info())  # (2261000645128, 10)
arr.remove(0)
print(arr)  # array('i', [1, 2, 3, 4, 5, 6, 7, 8, 9])
print(arr.count(0), arr.count(4))  # 0 1
print(arr.pop(), arr.pop(2), arr)  # 9 3 array('i', [1, 2, 4, 5, 6, 7, 8])
print(arr.append(100), arr.insert(0, 100), arr.insert(2, 100),
      arr)  # None None None array('i', [100, 1, 100, 2, 4, 5, 6, 7, 8, 100])
arr.fromlist([101, 102, 103])
print(arr)  # array('i', [100, 1, 100, 2, 4, 5, 6, 7, 8, 100, 101, 102, 103])
arr.reverse()
print(arr)  # array('i', [103, 102, 101, 100, 8, 7, 6, 5, 4, 2, 100, 1, 100])
print(arr.tolist())  # [103, 102, 101, 100, 8, 7, 6, 5, 4, 2, 100, 1, 100]
